<template>
  <div class="room-log">
    <div class="easy-content">
      <el-form>
        <el-form-item style="margin-bottom:0;">
          <div class="order-warpper">

            <div class="group-1">
              <el-cascader :options="deptList"
                :props="{ value: 'id', label: 'department', children: 'adminDepartments' }"
                v-model="dept"
                :show-all-levels="false"
                placeholder="请选择部门"
                 change-on-select
                clearable
                @change="setDeptId">
              </el-cascader>
            </div>
            <div class="group-1">
              <el-select v-model="moduleId"
                @change="_roomLogList"
                clearable
                placeholder="请选择模块">
                <el-option value="1"
                  label="查房报房"></el-option>
                <el-option value="2"
                  label="打扫"></el-option>
                <el-option value="3"
                  label="核房"></el-option>
              </el-select>
            </div>
            <div class="group-1"
              style="width:100px">
              <el-select v-model="timeId"
                @change="_roomLogList"
                clearable
                placeholder="请选择时间类型">
                <el-option value="1"
                  label="操作时间"></el-option>
                <el-option value="2"
                  label="完成时间"></el-option>
              </el-select>
            </div>
            <div class="group-2">
              <el-date-picker v-model="startEndTime"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @change="_roomLogList"
                value-format="yyyy-MM-dd">
              </el-date-picker>
            </div>
            <div class="group-1">
              <el-input placeholder="请输入账号/姓名/房间号"
                v-model="search"
                clearable>
              </el-input>
            </div>
            <el-button type="primary"
              @click.native="_roomLogList"
              class="searc"
              style=" line-height: 32px;padding: 0 21px;">
              <i class="el-icon-search"></i>
            </el-button>
          </div>
          <el-form-item>
            <el-button type="primary"
              class="searc"
              size="small"
              style="margin-top:20px;"
              :disabled = "!roomLogList.length"
              @click.native="_exportToLog"
              v-has="'logroomoutputlist'"
              >
              导出日志
            </el-button>
          </el-form-item>
        </el-form-item>
        <el-form-item class="easy-table">
          <el-table :data="roomLogList"
            style="width: 100%"
            max-height="600"
            >
            <el-table-column prop="num"
              label="日志编号"
              min-width="100">
            </el-table-column>
            <el-table-column prop="account"
              label="操作账号"
              min-width="100">
            </el-table-column>
            <el-table-column prop="name"
              label="操作姓名"
              min-width="100">
            </el-table-column>
            <el-table-column prop="dept"
              label="部门"
              min-width="100">
            </el-table-column>
            <el-table-column prop="module"
              label="操作模块"
              min-width="100">
            </el-table-column>
            <el-table-column prop="roomNum"
              label="操作房号"
              min-width="100">
            </el-table-column>
            <el-table-column prop="operationTime"
              label="操作时间"
              min-width="100">
            </el-table-column>
            <el-table-column prop="achieveTime"
              label="完成时间"
              min-width="100">
            </el-table-column>
            <el-table-column prop="type"
              label="操作结果"
              min-width="100">
            </el-table-column>
          </el-table>
        </el-form-item>
        <el-form-item>
          <el-pagination @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNo"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize"
            layout="total, prev , pager , next, sizes"
            :total="total"
            style="margin-top:20px">
          </el-pagination>
        </el-form-item>
      </el-form>

    </div>
  </div>
</template>
<script>
import { roomLogList, getExportRoomList } from "@/public/js/log";
import { getDeptstaffAll } from "@/public/js/setting";
import { exportToExcel } from "@/public/js/util";
export default {
  data() {
    return {
      roomLogList: [],
      deptId: "",
      startEndTime: [],
      deptList: [],
      dept: [],
      moduleId: "",
      timeId: "1",
      pageNo: 1,
      pageSize: 10,
      search: "",
      total: 0,
      props: {
        value: "id",
        children: "children",
        label: "label"
      },
      exportLogList: []
    };
  },
  created() {
    this.getDepList();
    this._roomLogList();
  },

  mounted() {},
  methods: {
    // 获取部门列表数据
    getDepList() {
      getDeptstaffAll().then(res => {
        if (res.data.errCode === 0) this.deptList = res.data.adminDepartments;
      });
    },
    // 获取日志列表
    _roomLogList() {
      roomLogList({
        pageSize: this.pageSize,
        pageNum: this.pageNo,
        search: this.search,
        deptId: this.deptId,
        moduleId: this.moduleId,
        timeId: this.timeId,
        startTime: this.startEndTime ? this.startEndTime[0] : "",
        endTime: this.startEndTime ? this.startEndTime[1] : ""
      }).then(res => {
        console.log("res****", res);
        this.roomLogList = res.data.roomLogList;
        this.total = res.data.total;
      });
    },
    // 设置部门
    setDeptId() {
      this.deptId = this.dept[this.dept.length - 1];
      this._roomLogList();
    },
    //获取导出房务日志数据
    _getExportLogList(callback) {
      getExportRoomList({
        search: this.search,
        deptId: this.deptId,
        moduleId: this.moduleId,
        timeId: this.timeId,
        startTime: this.startEndTime ? this.startEndTime[0] : "",
        endTime: this.startEndTime ? this.startEndTime[1] : ""
      }).then(res => {
        this.exportLogList = res.data.roomLogList;
        //回调函数
        callback();
      });
    },
     //导出日志
    _exportToLog() {
      this._getExportLogList(() => {
        const tHeader = [
          "日志编号",
          "操作账号",
          "操作姓名",
          "部门",
          "操作模块",
          "操作房号",
          "操作时间",
          "完成时间",
          "操作结果"
        ];
        const filterVal = [
          "num",
          "account",
          "name",
          "dept",
          "module",
          "roomNum",
          "operationTime",
          "achieveTime",
          "type"
        ];
        exportToExcel(tHeader, filterVal, this.exportLogList,'房务日志表');
      });
    },
    // 分页
    handleSizeChange(pageSize) {
      this.pageSize = pageSize;
      this._roomLogList();
    },
    handleCurrentChange(pageNo) {
      this.pageNo = pageNo;
      this._roomLogList();
    }
  }
};
</script>
<style lang="scss" scoped>
.order-warpper {
  .group-1 {
    width: 180px;
    display: inline-block;
    margin-right: 20px;
    .el-cascader,
    .el-select {
      width: 100%;
    }
  }
  .group-2 {
    width: 280px;
    display: inline-block;
    margin-right: 20px;
    .el-date-editor {
      width: 100%;
      padding: 0 10px;
    }
  }
  .group-3 {
    margin-top: 20px;
  }
  .btn {
    text-align: right;
  }
  .el-input__inner {
    height: 34px;
  }
  .search-button .el-button {
    padding: 9px 20px;
  }
}

.account-content {
  & > div {
    display: flex;
    padding-bottom: 15px;
    & > div {
      flex: 1;
    }
  }
}
.miNiCommListTable {
  border: 1px solid #ddd;
  border-right: 0;
  li {
    display: flex;
    border-bottom: 1px solid #ddd;

    div {
      flex: 1;
      line-height: 45px;
      font-size: 12px;
      text-indent: 23px;
      border-right: 1px solid #ddd;
    }
    &.header > div {
      background: #eef1f9;
      color: #415161;
    }
    & > .input-number .input-number-count {
      text-align: center;
      text-indent: 0;

      p {
        display: inline-block;
        background: #6d2377;
        height: 30px;
        line-height: 30px;
        width: 30px;
        border-radius: 5px 0 0 5px;
        color: #fff;
        cursor: pointer;
      }
      input {
        display: inline-block;
        height: 30px;
        line-height: 30px;
        border: none;
        width: 30px;
        text-align: center;
        border: 1px solid #6d2377;
        box-sizing: border-box;
      }
    }
  }
}
.handleBtn {
  float: left;
  height: 47px;
  line-height: 47px;
  padding-left: 15px;
  color: #409eff;
}
.inline-block {
  display: flex;
  & > div.el-form-item {
    flex: 1;
  }
}
</style>


